#ifndef __XMLNODE_HPP__
# define __XMLNODE_HPP__

#include <iostream>
#include <string>
#include <list>

#include "XMLAttribute.hpp"

class XMLNode
{
public:
    XMLNode(std::string buffer)
    {
        nodeName = buffer.substr(0, buffer.find_first_of(" \t"));
        size_t pos = buffer.find_first_of(" \t");
        while (pos < buffer.size())
        {
            pos = buffer.find_first_not_of(" \t", pos);
            if (pos >= buffer.size())
                break;
            std::string attrName(buffer.substr(pos, buffer.find("=", pos) - pos));
            pos = buffer.find("=", pos) + 1;
            std::string attrValue;
            if (pos < buffer.size())
                attrValue = buffer.substr(pos + 1, buffer.find(buffer[pos], pos + 1) - (pos + 1));
            pos = buffer.find(buffer[pos], pos + 1) + 1;
            this->attrList.push_back(new XMLAttribute(attrName, attrValue));
        }
    }

    virtual ~XMLNode() {}

    inline const std::string		getNodeName() const
    {
        return this->nodeName;
    }

    inline std::list<XMLAttribute*>*	getAttributes()
    {
        return &attrList;
    }

private:
    std::list<XMLAttribute*>	attrList;
    std::string					nodeName;
};

#endif
